package cn.stylefeng.guns.modular.agv.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.agv.entity.HikAgvRoadWayJL;
import cn.stylefeng.guns.modular.agv.mapper.HikAgvRoadWayJLMapper;
import cn.stylefeng.guns.modular.agv.model.params.HikAgvRoadWayJLParam;
import cn.stylefeng.guns.modular.agv.model.result.HikAgvRoadWayJLResult;
import  cn.stylefeng.guns.modular.agv.service.HikAgvRoadWayJlService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 吉林海康小车巷道情况 服务实现类
 * </p>
 *
 * @author lww
 * @since 2024-10-23
 */
@Service
public class HikAgvRoadWayJlServiceImpl extends ServiceImpl<HikAgvRoadWayJLMapper, HikAgvRoadWayJL> implements HikAgvRoadWayJlService {

    @Override
    public void add(HikAgvRoadWayJLParam param){
        HikAgvRoadWayJL entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(HikAgvRoadWayJLParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(HikAgvRoadWayJLParam param){
        HikAgvRoadWayJL oldEntity = getOldEntity(param);
        HikAgvRoadWayJL newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public HikAgvRoadWayJLResult findBySpec(HikAgvRoadWayJLParam param){
        return null;
    }

    @Override
    public List<HikAgvRoadWayJLResult> findListBySpec(HikAgvRoadWayJLParam param){
        return this.baseMapper.customList(param);

    }

    @Override
    public LayuiPageInfo findPageBySpec(HikAgvRoadWayJLParam param, String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(HikAgvRoadWayJLParam param){
        return param.getRoadWayCode();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private HikAgvRoadWayJL getOldEntity(HikAgvRoadWayJLParam param) {
        return this.getById(getKey(param));
    }

    private HikAgvRoadWayJL getEntity(HikAgvRoadWayJLParam param) {
        HikAgvRoadWayJL entity = new HikAgvRoadWayJL();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
